<template>
  <div class="container">
    <mt-header fixed :title="$route.meta.title">
      <span slot="left" @click="goBack" v-show="showBack">
        <mt-button icon="back">返回</mt-button>
      </span>
    </mt-header>
    <transition name="fade">
      <router-view></router-view>
    </transition>
    <tabbar></tabbar>
  </div>
</template>

<script>
//引入底部导航栏
import tabbar from "./components/tabbar.vue";

export default {
  data() {
    return {
      showBack: false //控制返回按钮为隐藏
    }
  },
  created() {
    this.showBack = this.$router.path !== "/home"; //初始化判断部位首页，判断是否显示返回按钮
  },
  watch: {
    "$router.path"(newVal) {
      this.showBack = newVal !== "/home"; //等于home时，showback为false不显示返回，否则显示返回
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1) //返回上一个页面
    }
  },
  components: {
    tabbar//添加底部导航按钮
  }
};
</script>

 <style lang="scss" scoped>
#app {
  font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
  text-align: center;
  color: #2c3e50;
  box-shadow: border-box;
}
.container {
  padding-top: 40px;
  padding-bottom: 50px;
  overflow-x: hidden;
}
.fade-enter {
  opacity: 0;
  transform: translateX(100%);
}
.fade-leave-active {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.fade-enter-avtive,
.fade-leave-active {
  transition: all 0.5s ease;
}
</style>


